<template>
  <div class="sc-AxmLO gmtmqV">
    <div class="sc-fzokOt hLgJkJ">
      <h2>Recommended</h2>
      <div class="sc-fzoLsD fYZyZu">
        <router-link v-for="(item, index) in videos" :key="index" :to="`/watch/${item._id}`"
          ><div class="sc-fzozJi dteCCc">
            <img
              class="thumb"
              :src="item.cover"
              alt="thumbnail"
            />
            <div class="video-info-container">
              <div class="channel-avatar">
                <img
                  src="@/assets/pig.jpeg"
                  alt=""
                  class="sc-AxhCb eSwYtm"
                  style="margin-right: 0.8rem"
                />
              </div>
              <div class="video-info">
                <h4>{{ item.title }}</h4>
                <span class="secondary">{{ item.user.username }}</span>
                <p class="secondary">
                  <span>{{ item.viewsCount }} views</span> <span>•</span> <span>{{ item.createdAt }}</span>
                </p>
              </div>
            </div>
          </div>
        </router-link>
        <!-- <a href="/watch/3ac30e23-45a6-4eca-9430-3654142a772c"
          ><div class="sc-fzozJi dteCCc">
            <img
              class="thumb"
              src="https://res.cloudinary.com/tylerdurden/video/upload/v1610602989/youutbeclone/jcxdkn7kwykw2oyk95up.jpg"
              alt="thumbnail"
            />
            <div class="video-info-container">
              <div class="channel-avatar">
                <img
                  src="https://res.cloudinary.com/tylerdurden/image/upload/v1610602675/youutbeclone/cyytoyb0dtzouizokimz.jpg"
                  alt="channel avatar"
                  class="sc-AxhCb eSwYtm"
                  style="margin-right: 0.8rem"
                />
              </div>
              <div class="video-info">
                <h4>Twitter clone</h4>
                <span class="secondary">manikandanraji</span>
                <p class="secondary">
                  <span>6 views</span> <span>•</span> <span>22 days ago</span>
                </p>
              </div>
            </div>
          </div></a
        > -->
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { getVideos, Video } from '@/api/video'
import { defineComponent, ref } from 'vue'

const queryVideos = async () => {
  const videos = ref<Array<Video> | null>(null)
  try {
    const data = await getVideos()
    videos.value = data.data.videos
    console.log(videos.value)
  } catch (error) {
    console.log(error)
  }
  return {
    videos
  }
}

export default defineComponent({
  name: 'Home',
  async setup () {
    const videos = await queryVideos()
    return {
      test: true,
      ...videos
    }
  }
})
</script>
